package operation;
import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements Ioperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书");
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入你要新增的图书名：");
        String name = scanner.nextLine();
        System.out.println("请输入你要新增的图书作者：");
        String author = scanner.nextLine();
        System.out.println("请输入你要新增的图书价格：");
        int price = scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入你要新增的图书类型：");
        String type = scanner.nextLine();

        //创建新书
        Book book = new Book(name, author, price, type);
        //获取当前已有图书数量
        int currentSize = bookList.getUsedSize();
        //把书放入指定位置
        bookList.setBooks(book, currentSize);
        //书个数加一
        bookList.setUsedSize(currentSize + 1);

        System.out.println("添加成功！");
    }
}